let uid =0;
/**
 * @description Dep类用来收集依赖，核心是观察者模式，收集的是Watcher实例（组件也是Watcher实例）
 */
class Dep {
    constructor(){
        this.id = uid++;
        this.subs = [] 
    }
    /**
     * @description 收集依赖
     */
    depend(){
        if(Dep.target){
            Dep.target.addDep(this)  //Watcher和Dep互相记忆
        }   
    }
    /**
     * @description 通知更新
     */
    notify(){
       this.subs.forEach((watcher)=>watcher.update())
    }
    /**
     * @description 订阅
     */
    addSub(watcher){
       this.subs.push(watcher)  
       console.log(this.subs)
    }
    /**
     * @description 移除依赖
     */
    removeSub(){}
}
let stack = []
/**
 * 保存当前的watcher
 * @param {*} watcher 
 */
export function pushTarget(watcher){
   Dep.target = watcher
   stack.push(watcher)
}
export function popTarget(){
   stack.pop()
   Dep.target = stack[stack.length -1]
}
export default Dep